package zpe.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import zpe.genericcrud.model.Entidade;

@Entity
@Table(name = "tb_enderecamento", schema = "dbo")
public class Enderecamento implements Entidade {

	private static final long serialVersionUID = 3176814900832143343L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ci_enderecamento")
	private Integer id;
	
	@OneToOne
	@JoinColumn( name = "cd_carga" , nullable = false)
	private Carga carga = new Carga();
	
	@OneToMany(mappedBy = "enderecamento", targetEntity = EnderecamentoHistorico.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true )
	private List<EnderecamentoHistorico> historico = new ArrayList<EnderecamentoHistorico>();
	
	@OneToOne
	@JoinColumn( name = "cd_conteiner" , nullable = true)
	private Conteiner conteiner = new Conteiner();
	
	@Column(name = "nr_quantidade")
	private Integer quantidade;
	
	@Transient
	private String Descricao;
	
	public Enderecamento(){
	}
	
	public Integer getId() {
		return id;
	}

	public String getDescricao() {
		return Descricao;
	}

	public Integer getQuantidade() {
		return quantidade;
	}

	public void setQuantidade(Integer quantidade) {
		this.quantidade = quantidade;
	}

	public Carga getCarga() {
		return carga;
	}

	public void setCarga(Carga carga) {
		this.carga = carga;
	}

	public List<EnderecamentoHistorico> getHistorico() {
		return historico;
	}

	public void setHistorico(List<EnderecamentoHistorico> historico) {
		this.historico = historico;
	}

	public void setDescricao(String descricao) {
		Descricao = descricao;
	}

	public Conteiner getConteiner() {
		return conteiner;
	}

	public void setConteiner(Conteiner conteiner) {
		this.conteiner = conteiner;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public Map<String, Object> notEmptyFields() {
		Map<String, Object> map = new HashMap<String, Object>();
		return map;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Enderecamento other = (Enderecamento) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
